<?php


namespace EchoPHP\Database;


use EchoPHP\Foundation\ServiceProvider;

class DatabaseServiceProvider extends ServiceProvider {

    protected $defer = true;

    public function register() {
        //注册数据库连接生产工厂
        $this->app->singleton('db.factory', function () {
            return new ConnectionFactory($this->app);
        });
        //注册数据库操作类
        $this->app->singleton('db', function () {
            return new DatabaseManager($this->app, $this->app['db.factory']);
        });
        //注册连接实例
        $this->app->bind('db.connection', function () {
            return $this->app['db']->connect();
        });
    }

    public function provides() {
        return ['db.factory', 'db', 'db.connection'];
    }
}